//
//  AppDelegate.m
//  YJB
//
//  Created by 中电大维 on 16/5/12.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "AppDelegate.h"
#import "YJLoginVC.h"
#import "YJRegistVC.h"
#import "YJNetworkTool.h"
#import "YJUserDefaultTool.h"
#import "IQKeyboardManager.h"
#import <AudioToolbox/AudioToolbox.h>
#import "SDWebImageManager.h"
#import "YJVersionTool.h"
//友盟统计工具
//#import "UMMobClick/MobClick.h"
#import <UserNotifications/UserNotifications.h>
#import "YJGlobalHeader.h"
#import "YJBaseNav.h"

#import "RealReachability.h"
#import "Reachability.h"

@interface AppDelegate ()<SRWebSocketDelegate>
@property(nonatomic,assign)BOOL isSilenceMode;
@end
@implementation AppDelegate
//@synthesize myObject = _myObject的含义就是属性myObject的存取方法是作用于_myObject这个变量的。
@synthesize isConnectWebsocket = _isConnectWebsocket;
@synthesize isObtainOfflineMsg = _isObtainOfflineMsg;
static dispatch_queue_t myconcurrentQueueOne;
static dispatch_queue_t myconcurrentQueueTwo;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     myconcurrentQueueOne = dispatch_queue_create("myconcurrentQueueOne", DISPATCH_QUEUE_CONCURRENT);
     myconcurrentQueueTwo = dispatch_queue_create("myconcurrentQueueTwo", DISPATCH_QUEUE_CONCURRENT);
    
    self.isSilenceMode = [YJUserDefaultTool readIsSilenceMode];
    [[[NOTIFICATIONCENTER rac_addObserverForName:YJAppSilenceModeDidChangeNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *x) {
        self.isSilenceMode = [x.userInfo[@"isSilenceModel"] boolValue];
    }];
    //注册APNS
//    if ([UIDevice currentDevice].systemVersion.doubleValue < 8.0) {
//        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
//    }else
//    {
//        [[UIApplication sharedApplication] registerForRemoteNotifications];
//        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]];
//    }
    
#ifndef DEBUG
//    UMConfigInstance.appKey = @"580ed35ec8957676180023b7";
//    UMConfigInstance.channelId = @"App Store";
//    [MobClick startWithConfigure:UMConfigInstance];
//    NSString *appVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
//    [MobClick setAppVersion:appVersion];
#endif
    
    //若当前版本与该版本不一致，则修改登录状态，从而重新登录
    [YJVersionTool showGuideView:^{
        [YJUserDefaultTool saveLoginStatus:NO];
    }];
   
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
//    if ([YJUserDefaultTool readLoginStatus])
//        self.window.rootViewController = [YJTabBarC new];
//    else
//    {
//      YJBaseNav *loginVC = [[YJBaseNav alloc]initWithRootViewController:[YJLoginVC new]];
//      self.window.rootViewController = loginVC;
//    }
//    YJBaseNav *loginVC = [[YJBaseNav alloc]initWithRootViewController:[YJLoginVC new]];
    
//    THTabBarC *vc = [[THTabBarC alloc] init];
    Class clasz = NSClassFromString(@"THTabBarC");
    YJBaseNav *nav = [[YJBaseNav alloc] initWithRootViewController:[[clasz alloc]init]];
    
    self.window.rootViewController = nav;
    
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    [manager setEnableAutoToolbar:NO];
    [manager shouldResignOnTouchOutside];
    [self.window makeKeyAndVisible];
    

    
    return YES;
}

//- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
//{
//    NSString *token = [[[[deviceToken description]
//  stringByReplacingOccurrencesOfString:@"<" withString:@""]stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""];
//    MyLog(@"获取到的token ===== %@",token);
//    [YJUserDefaultTool saveToken:token];
//    //发通知上传token
//    [NOTIFICATIONCENTER postNotificationName:YJAPPDidGetDeviceTokenNotification object:nil];
//}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}


-(void)dealloc
{
    [NOTIFICATIONCENTER removeObserver:self];
}


@end
